Skip to content

fix: auto-select a company when no default is set (#4)#8

Merged
NagariaHussain merged 2 commits into
developfrom
fix/default-company-selection
Jun 4, 2026
Merged

fix: auto-select a company when no default is set (#4)#8
NagariaHussain merged 2 commits into
developfrom
fix/default-company-selection

Conversation

@NagariaHussain
Copy link
Copy Markdown
Contributor

Problem

Opening Ledger Lab with no default company set showed a warning —
"No company found. Please set a default company." — and empty boxes (—).

Closes #4

Fix

  • init_company() (new): before the first load, if Frappe's client default
    (frappe.defaults.get_default("company")) is unset, fall back to the first
    available Company (oldest first) and select it in the header picker. The page
    now always opens with data instead of erroring out.
  • refresh() picker sync: reflect the server-resolved company in the header
    field so it never shows blank while data is loaded (covers the
    global-default-only case). The existing change-handler guard (val !== this.company)
    prevents a reload loop on programmatic set_value.

No backend changes.

Verification (agent-browser, ledger.localhost)

Case Before After
No global/user default company ⚠️ warning + empty boxes ✅ falls back to BWH, data loads, no warning
Defaults present (normal) ✅ works ✅ still selects BWH, data loads

Defaults were temporarily cleared to reproduce, then restored.

🤖 Generated with Claude Code

NagariaHussain and others added 2 commits June 4, 2026 12:09
Task: Ledger Lab page opened with no default company showed "No company
found. Please set a default company." and empty boxes (GitHub issue #4).

Key decisions:
- Frontend now resolves a company before the first load: if Frappe's
  client default ("company") is unset, fall back to the first available
  Company (frappe.db.get_list, oldest first) so the page always opens
  with data instead of erroring out.
- refresh() also syncs the header picker to the server-resolved company,
  so the field never shows blank while data is loaded (covers the
  global-default-only case). The change-handler guard prevents a reload
  loop on programmatic set_value.

Files changed:
- ledger_lab/ledger_lab/page/ledger_lab/ledger_lab.js
  (new async init_company(); constructor sequencing; refresh() picker sync)

Verified (agent-browser, ledger.localhost):
- Cleared global + user company defaults -> reproduced the warning/empty
  boxes, then confirmed fix falls back to BWH and loads data, no warning.
- Restored defaults -> normal case still selects BWH, loads data.

Notes for next iteration: only one company (BWH) exists on this bench, so
company-switching wasn't re-exercised (logic unchanged). Issue #5 (basic
transaction-list filters: show-cancelled, root-type) remains open.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…y-selection

# Conflicts:
#	ledger_lab/ledger_lab/page/ledger_lab/ledger_lab.js
@NagariaHussain NagariaHussain merged commit fac8941 into develop Jun 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default company must be selected when ledger lab page is opened

1 participant